//
//  MYStatusToolBarView.swift
//  Sina
//
//  Created by 王亮龙1 on 16/5/25.
//  Copyright © 2016年 lianglong. All rights reserved.
//

import UIKit
import SnapKit

class MYStatusToolBarView: UIView {
    
    var statusViewModel: MYStatusViewModel? {
        didSet {
            
            retweetBtn.setTitle(statusViewModel?.repostTitle, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.commentTitle, forState: .Normal)
            likeBtn.setTitle(statusViewModel?.likeTitle, forState: .Normal)
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //布局子控件
    private func setupUI() {
        
        addsubBtn(retweetBtn, title: "转发", imageName: "timeline_icon_retweet")
        addsubBtn(commentBtn, title: "评论", imageName: "timeline_icon_comment")
        addsubBtn(likeBtn, title: "赞", imageName: "timeline_icon_like")
        
        
        
        //设置约束
        retweetBtn.snp_makeConstraints { (make) in
            make.left.bottom.top.equalTo(self)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        commentBtn.snp_makeConstraints { (make) in
            make.left.equalTo(retweetBtn.snp_right)
            make.top.bottom.equalTo(self)
            make.width.equalTo(likeBtn.snp_width)
        }
        
        likeBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.right.equalTo(self)
            make.top.bottom.equalTo(self)
        }
        
        let lineView1: UIView = lineView()
        let lineView2: UIView = lineView()
        addSubview(lineView1)
        addSubview(lineView2)
        
        let width = 1 / UIScreen.mainScreen().scale
        
        lineView1.snp_makeConstraints { (make) in
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
            make.right.equalTo(commentBtn.snp_left)
            make.centerY.equalTo(self.snp_centerY)
        }
        
        lineView2.snp_makeConstraints { (make) in
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
            make.right.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
        }

        
    }
    
    //设置分割线的方法
    private func lineView() -> UIView {
        
        let lineView: UIView = UIView()
        lineView.backgroundColor = UIColor.darkGrayColor()
        
        return lineView
    }
    
    
    //设置btn的方法
    private func addsubBtn(btn: UIButton, title: String, imageName: String) {
        
        btn.adjustsImageWhenHighlighted = false
        
        btn.setTitle(title, forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        
        btn.sizeToFit()
        self.addSubview(btn)
    }
    
    
    
    //懒加载子控件
    private lazy var retweetBtn: UIButton = UIButton()
    private lazy var commentBtn: UIButton = UIButton()
    private lazy var likeBtn: UIButton = UIButton()

    

}
